package com.mzwise.tunnel.utils;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * json 相关工具类
 * @author wmf
 */

public class JsonUtils {
    public static String toJson(Object obj) {
        Gson gson = new GsonBuilder()
                .setPrettyPrinting()
                .create();
        return gson.toJson(obj);
    }

    public static String toJsonUnderscore(Object obj) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
        gsonBuilder.setDateFormat("YYY-MM-dd'T'HH:mm:ss'.'sss'+08:00'");
        Gson gson = gsonBuilder.create();
        return gson.toJson(obj);
    }
}
